/*****************************************************************************
 *                                                                            *
 *                     OS configuration body file                             *
 *                                                                            *
 *----------------------------------------------------------------------------*

 *-------------------------------------------------------------------
 * to avoid multiple definition if the file is included several times
 *-------------------------------------------------------------------
 *****************************************************************************/
#ifndef OS_CFG_H
#define OS_CFG_H

#include <mc9s12dp256.h>

/*----------------------------------------------------------------------------*
 *                     --- Local constants & typedefs ---                     *
 *----------------------------------------------------------------------------*/

/*
	This section defines the basic object types used by OS.
	They must be checked and configured for each target.
*/
typedef unsigned short	OS_IndexType;		// Used for array index, must be unsigned and fastest target type for performance optimisation
typedef unsigned short	OS_TimeType;		// Used for time representation, must be unsigned and sized for holding the max timer value (8 bits for max timer value <= 255)
typedef unsigned short	OS_BoolType;		// Boolean type, must be unsigned and fastest target type for performance optimisation

#define OS_TRUE			(OS_BoolType)1
#define OS_FALSE		(OS_BoolType)0


// Define here the OS tick (in ms)
#define OS_SYS_TICK		1 		// OS tick is 1 ms
// Define here the OS oscillator frequency (in Mhz)
#define OS_OSC_FREQUENCY	(16000000L/2) 	// System Frequency is 16 MHz
#define OS_OSC_PLL_FACTOR	1 	// System Frequency is XX MHz
// If something to do at the very begining of the SysTick routine
#define OS_PRE_SYSTICK()  TC4 += OS_TIMER_PERIOD; TFLG1_C4F = 1
// If something to do at the very end of the SysTick routine
#define OS_POST_SYSTICK()

// Define it if your system has permanent 1 tick timer(s)
//#define OS_1TICK_TIMER_OPTIMISED

#define OS_TIMER_PERIOD     ((word)((OS_OSC_FREQUENCY/1000L)*(OS_SYS_TICK)))

#define OS_GetFreeRunCounter() TCNT

#pragma CODE_SEG NON_BANKED
__interrupt void OS_SysTick(void);
#pragma CODE_SEG DEFAULT


#define OS_TASK_USED
typedef enum
{
    OS_TaskScan,
    OS_TaskRefresh,
    OS_TaskChecker,
    OS_MaxTask
} OS_TaskID;


typedef enum
{
	// Insert here interrupts ID
	OS_MaxInterrupt
} OS_InterruptID;


/*----------------------------------------------------------------------------*
 *                         --- Global Variables ---                           *
 *----------------------------------------------------------------------------*/



/*----------------------------------------------------------------------------*
 *                          --- Public functions ---                          *
 *----------------------------------------------------------------------------*/
 
#define OS_SoftwareReset() while(1)
 
#ifdef __cplusplus
extern "C"
{
#endif


// Map OS_DisableSysTick & OS_EnableSysTick to System Tick timer interrupt
#ifdef _WIN32
    #define OS_EnableAllInterrupts()
    #define OS_DisableAllInterrupts()

    #define OS_DisableSysTick()
    #define OS_EnableSysTick()
    #define OS_SysTickPre()
    #define OS_SysTickPost()
#else
    #define OS_EnableAllInterrupts()  asm CLI;
    #define OS_DisableAllInterrupts() asm SEI;

    #define OS_DisableSysTick() TIE_C4I = 0
    #define OS_EnableSysTick()  TIE_C4I = 1
    #define OS_SysTickPre()     TC4 += OS_TIMER_PERIOD; TFLG1_C4F = 1;/* PTP |= 0x20*/
    #define OS_SysTickPost()    /* PTP &= ~0x20 */

#endif

#ifdef __cplusplus
}
#endif


#endif /* OS_Cfg_h*/
/******************************************************************************
 *                               End of file                                  *
 ******************************************************************************/

